home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / guile-ii.src / guile-ii / guile-src / slib / chez.init < prev    next >
Encoding:
Text File  |  1995-01-04  |  7.0 KB  |  267 lines

  1. ;"chez.init" Initialization file for SLIB for Chez Scheme    -*-scheme-*-
  2. ; Copyright (C) 1993 dorai@cs.rice.edu (Dorai Sitaram)
  3. ; Copyright (C) 1991, 1992, 1993 Aubrey Jaffer.
  4. ;
  5. ;Permission to copy this software, to redistribute it, and to use it
  6. ;for any purpose is granted, subject to the following restrictions and
  7. ;understandings.
  8. ;
  9. ;1.  Any copy made of this software must include this copyright notice
  10. ;in full.
  11. ;
  12. ;2.  I have made no warrantee or representation that the operation of
  13. ;this software will be error-free, and I am under no obligation to
  14. ;provide any services, by way of maintenance, update, or otherwise.
  15. ;
  16. ;3.  In conjunction with products arising from the use of this
  17. ;material, there shall be no use of my name in any advertising,
  18. ;promotional, or sales literature without prior written consent in
  19. ;each case.
  20.  
  21. ;;; (software-type) should be set to the generic operating system type.
  22. ;;; UNIX, VMS, MACOS, AMIGA and MS-DOS are supported.
  23.  
  24. (define (software-type) 'UNIX)
  25.  
  26. (define (scheme-implementation-type) 'Chez)
  27.  
  28. ;;; (scheme-implementation-version) should return a string describing
  29. ;;; the version the scheme implementation loading this file.
  30.  
  31. (define (scheme-implementation-version) "?")
  32.  
  33. (define implementation-vicinity
  34.   (lambda () "/usr/local/lib/scheme/"))
  35.  
  36. ;; library-vicinity is moved below the defination of getenv
  37.  
  38. (define *features*
  39.   '(
  40.     source                ;can load scheme source files
  41.                     ;(slib:load-source "filename")
  42.     compiled                ;can load compiled files
  43.                     ;(slib:load-compiled "filename")
  44.     char-ready?
  45.     delay
  46.     dynamic-wind
  47.     fluid-let
  48.     format
  49.     full-continuation
  50.     getenv
  51.     ieee-p1178
  52.     macro
  53.     multiarg/and-
  54.     multiarg-apply
  55.     pretty-print
  56.     random
  57.     random-inexact
  58.     rationalize
  59.     rev3-procedures
  60.     rev3-report
  61.     rev4-optional-procedures
  62.     rev4-report
  63.     sort
  64.     system
  65.     transcript
  66.     with-file
  67.     string-port
  68.     ))
  69.  
  70. ;R4RS define-syntax in terms of Chez's extend-syntax.
  71. ;Caveat: no let-syntax
  72.  
  73. (extend-syntax (define-syntax syntax-rules)
  74.   ((define-syntax name (syntax-rules kwds . clauses))
  75.    (extend-syntax (name . kwds) . clauses)))
  76.  
  77. ;DEFINED?
  78. (define-syntax defined?
  79.   (syntax-rules ()
  80.     ((defined? x) (or (bound? 'x) (get 'x '*expander*)))))
  81.  
  82. ;Chez's sort routines have the opposite parameter order to Slib's
  83. (define chez:sort sort)
  84. (define chez:sort! sort!)
  85. (define chez:merge merge)
  86. (define chez:merge! merge!)
  87.  
  88. (define sort
  89.   (lambda (s p)
  90.     (chez:sort p s)))
  91. (define sort!
  92.   (lambda (s p)
  93.     (chez:sort! p s)))
  94. (define merge
  95.   (lambda (s1 s2 p)
  96.     (chez:merge p s1 s2)))
  97. (define merge!
  98.   (lambda (s1 s2 p)
  99.     (chez:merge! p s1 s2)))
  100.  
  101. ;RENAME-FILE
  102. (define rename-file
  103.   (lambda (src dst)
  104.     (system (string-append "mv " src " " dst))))
  105.  
  106. ;OUTPUT-PORT-WIDTH
  107. (define output-port-width (lambda arg 79))
  108.  
  109. ;;; (OUTPUT-PORT-HEIGHT <port>)
  110. (define (output-port-height . arg) 24)
  111.  
  112. ;;; (CURRENT-ERROR-PORT)
  113. (define current-error-port
  114.   (let ((port (current-output-port)))
  115.     (lambda () port)))
  116.  
  117. ;;; (TMPNAM) makes a temporary file name.
  118. (define tmpnam
  119.   (let ((cntr 100))
  120.     (lambda () (set! cntr (+ 1 cntr))
  121.         (let ((tmp (string-append "slib_" (number->string cntr))))
  122.           (if (file-exists? tmp) (tmpnam) tmp)))))
  123.  
  124. ;GETENV
  125. (provide-foreign-entries '("getenv"))
  126. (define getenv
  127.   (foreign-procedure "getenv"
  128.     (string) string))
  129.  
  130. (define library-vicinity
  131.   (let ((library-path (or (getenv "SCHEME_LIBRARY_PATH")
  132.               "/usr/local/lib/slib/")))
  133.     (lambda () library-path)))
  134.  
  135. ;FORCE-OUTPUT
  136. (define force-output flush-output)
  137.  
  138. ;;; CALL-WITH-INPUT-STRING and CALL-WITH-OUTPUT-STRING are the string
  139. ;;; port versions of CALL-WITH-*PUT-FILE.
  140. (define (call-with-output-string f)
  141.   (let ((outsp (open-output-string)))
  142.     (f outsp)
  143.     (let ((s (get-output-string outsp)))
  144.       (close-output-port outsp)
  145.       s)))
  146.  
  147. (define (call-with-input-string s f)
  148.   (let* ((insp (open-input-string s))
  149.      (res (f insp)))
  150.     (close-input-port insp)
  151.     res))
  152.  
  153. ;CHAR-CODE-LIMIT
  154. (define char-code-limit 256)
  155.  
  156. ;Chez's MOST-POSITIVE-FIXNUM is a thunk rather than a number
  157. (if (procedure? most-positive-fixnum)
  158.     (set! most-positive-fixnum (most-positive-fixnum)))
  159.  
  160. ;;; Return argument
  161. (define (identity x) x)
  162.  
  163. (define slib:eval eval)
  164.  
  165. (define-macro! defmacro z `(define-macro! ,@z))
  166.  
  167. (define (defmacro? m) (get m '*expander*))
  168.  
  169. (define macroexpand-1 eps-expand-once)
  170.  
  171. (define (macroexpand e)
  172.   (if (pair? e) (let ((a (car e)))
  173.           (if (and (symbol? a) (getprop a '*expander*))
  174.               (macroexpand (expand-once e))
  175.               e))
  176.       e))
  177.  
  178. (define gentemp
  179.   (let ((*gensym-counter* -1))
  180.     (lambda ()
  181.       (set! *gensym-counter* (+ *gensym-counter* 1))
  182.       (string->symbol
  183.        (string-append "slib:G" (number->string *gensym-counter*))))))
  184.  
  185. (define defmacro:eval slib:eval)
  186. (define macro:eval slib:eval)
  187.  
  188. (define (slib:eval-load <pathname> evl)
  189.   (if (not (file-exists? <pathname>))
  190.       (set! <pathname> (string-append <pathname> (scheme-file-suffix))))
  191.   (call-with-input-file <pathname>
  192.     (lambda (port)
  193.       (let ((old-load-pathname *load-pathname*))
  194.     (set! *load-pathname* <pathname>)
  195.     (do ((o (read port) (read port)))
  196.         ((eof-object? o))
  197.       (evl o))
  198.     (set! *load-pathname* old-load-pathname)))))
  199.  
  200. ;Chez's (FORMAT f . a) corresponds to Slib's (FORMAT #f f . a)
  201.  
  202. (define chez:format format)
  203. (define format
  204.   (lambda (where how . args)
  205.     (let ((str (apply chez:format how args)))
  206.       (cond ((not where) str)
  207.         ((eq? where #t) (display str))
  208.         (else (display str where))))))
  209.  
  210. (define slib:error
  211.   (lambda args
  212.     (let ((port (current-error-port)))
  213.       (display "Error: " port)
  214.       (for-each (lambda (x) (display x port)) args)
  215.       (error #f ""))))
  216.  
  217. (define slib:tab #\tab)
  218. (define slib:form-feed #\page)
  219.  
  220. ;Chez's nil variable is bound to '() rather than #f
  221.  
  222. (define nil #f)
  223.  
  224. (define in-vicinity string-append)
  225.  
  226. ;;; Define SLIB:EXIT to be the implementation procedure to exit or
  227. ;;; return if exitting not supported.
  228. (define slib:chez:quit
  229.   (let ([arg (call-with-current-continuation (lambda (x) x))])
  230.     (cond [(procedure? arg) arg]
  231.       [arg (exit)]
  232.       [else (exit 1)])))
  233.  
  234. (define slib:exit
  235.   (lambda args
  236.     (cond ((null? args) (slib:chez:quit #t))
  237.       ((eqv? #t (car args)) (slib:chez:quit #t))
  238.       ((eqv? #f (car args)) (slib:chez:quit #f))
  239.       ((zero? (car args)) (slib:chez:quit #t))
  240.       (else (slib:chez:quit #f)))))
  241.  
  242. ;;; Here for backward compatability
  243. ;Note however that ".ss" is a common Chez file suffix
  244. (define (scheme-file-suffix) ".scm")
  245.  
  246. ;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever
  247. ;;; suffix all the module files in SLIB have.  See feature 'SOURCE.
  248.  
  249. (define (slib:load-source f) (load (string-append f (scheme-file-suffix))))
  250.  
  251. ;;; defmacro:load and macro:load also need the default suffix
  252. (define defmacro:load slib:load-source)
  253. (define macro:load slib:load-source)
  254.  
  255. ;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced
  256. ;;; by compiling "foo.scm" if this implementation can compile files.
  257. ;;; See feature 'COMPILED.
  258.  
  259. (define slib:load-compiled load)
  260.  
  261. ;;; At this point SLIB:LOAD must be able to load SLIB files.
  262.  
  263. (define slib:load slib:load-source)
  264.  
  265. (slib:load (in-vicinity (library-vicinity) "require"))
  266. ;end chez.init
  267.